package cn.itcast.algorithm.ch1;

public class SumTest {
    public static void main(String[] args) {
        // 不同处理器之间执行消耗的时间也有差异
        long start = System.currentTimeMillis();
        int sum = 0;
        int n = 100;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        System.out.println("sum=" + sum);
        long end = System.currentTimeMillis();
        System.out.println(start - end);
    }

    public static void main1(String[] args) {
        int sum = 0;
        int n = 100;
        sum = (n + 1) * n / 2; // 高斯公式
        System.out.println("sum=" + sum);

        // 对数阶 O(logn)
//        int i = 1;
//        int n = 100;
//        while (i < n) {
//            i = i * 2;
//        }
        // 时间复杂度从低到高
//        O(1)<O(logn)<O(n)<O(nlogn)<O(n^2)<O(n^3)
    }
}
